home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / OnRamp / bin / html.pl.z / html.pl
Encoding:
Perl Script  |  2002-06-12  |  8.1 KB  |  331 lines

  1. #!/usr/bin/perl5
  2. #
  3. # html.pl
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: html.pl,v 1.1 1997/11/18 22:36:08 jrw Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. $title = $ARGV[0];
  25. $root_dir = "$document_root/apps/majordomo/$title";
  26. $url_root = $ENV{'SERVER_URL'} . "/apps/majordomo/$title";
  27. $dummy = $root_dir . "/dummy";
  28. $num_file = "$root_dir/num";
  29. $subject_file = "$root_dir/subject.html";
  30. $author_file = "$root_dir/author.html";
  31. $date_file = "$root_dir/date.html";
  32.  
  33. &get_previous;
  34. &get_letter;
  35. &make_new_file;
  36. &fix_last_file;
  37. &make_authors;
  38. &make_subjects;
  39. &make_dates;
  40.  
  41. sub make_dates {
  42.     if ($num == 0) {
  43.         open(OUT, "> $date_file");
  44.         print OUT "<title>$title by date</title>\n"
  45.             . "<a href=\"date.html\">[date]</a>\n"
  46.             . "<a href=\"subject.html\">[subj]</a>\n"
  47.             . "<a href=\"author.html\">[auth]</a>\n"
  48.             . "<h1>$title by date</h1>\n"
  49.             . "<!-- DATE: $date-->\n";
  50.         print OUT "<ul>\n";
  51.         print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
  52.         print OUT "</ul>\n";
  53.     } else {
  54.         open(IN, "< $date_file");
  55.         open(OUT, "> $dummy");
  56.         while(<IN>) {
  57.             if ($_ =~ /\<\/ul/) {
  58.                 print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
  59.                 print OUT "</ul>\n";
  60.             } else { print OUT $_; }
  61.         }
  62.         close(IN);
  63.         close(OUT);
  64.         
  65.         rename($dummy, $date_file);
  66.     }
  67. }
  68.  
  69. sub make_subjects {
  70.     if ($num == 0) {
  71.         open(OUT, "> $subject_file");
  72.         print OUT "<title>$title by subject</title>\n"
  73.             . "<a href=\"date.html\">[date]</a>\n"
  74.             . "<a href=\"subject.html\">[subj]</a>\n" 
  75.             . "<a href=\"author.html\">[auth]</a>\n"
  76.             . "<h1>$title by subject</h1>\n"
  77.             . "<!-- SUBJECT: $subject-->\n";
  78.         print OUT "<b>$subject</b>\n<ul>\n";
  79.         print OUT "<li><a href=$url>$author</a> <i>$date</i>\n";
  80.         print OUT "</ul>\n";
  81.         print OUT "<!-- LAST -->\n";
  82.         close(OUT);
  83.     } else {
  84.         open(IN, "< $subject_file");
  85.         open(OUT, "> $dummy");
  86.         if ($subject =~ /^[rR]e: (.*)/) {
  87.             $short_sub = $1;
  88.             $not_done = 1;
  89.             while(<IN>) {
  90.                 $line = $_;
  91.                 if ($not_done && $_ =~ /\<\!-- SUBJECT\: (.*)--/) {    
  92.                     $nsub = $1; undef $short_nsub; 
  93.                     if ($nsub =~ /^[rR]e: (.*)/) { $short_nsub = $1; }
  94.                     if ($short_sub eq $nsub || $short_sub eq $short_nsub) {
  95.                         &append_subject;
  96.                         $not_done = 0;
  97.                     } else { print OUT $line; }
  98.                 } elsif ($not_done && $_ =~ /\<\!-- LAST --\>/) {
  99.                     &new_subject;
  100.                     print OUT $line;
  101.                 } else { print OUT $line; }
  102.             }
  103.         } else {
  104.             while(<IN>) {
  105.                 if ($_ =~ /\<\!-- LAST --\>/) {
  106.                     &new_subject;
  107.                     print OUT $_;
  108.                 } else { print OUT $_; }
  109.             }
  110.         }
  111.         close(OUT);
  112.         close(IN);
  113.  
  114.         rename($dummy, $subject_file);
  115.     }
  116. }
  117.  
  118. sub append_subject {
  119.     print OUT $line;
  120.     while(<IN>) {
  121.         if ($_ =~ /\<\/ul/) {
  122.             print OUT "<li><a href=$url>$author</a> <i>$date</i>\n"
  123.                 . "</ul>\n";
  124.             return;
  125.         } else { print OUT $_; }
  126.     }
  127. }
  128.  
  129. sub new_subject {
  130.     print OUT "<!-- SUBJECT: $subject-->\n";
  131.     print OUT "<b>$subject</b>\n<ul>\n";
  132.     print OUT "<li><a href=$url>$author</a> <i>$date</i>\n";
  133.     print OUT "</ul>\n";
  134. }
  135.  
  136. sub make_authors {
  137.     if ($num == 0) {
  138.         open(OUT, "> $author_file");
  139.         print OUT "<title>$title by author</title>\n"
  140.             . "<a href=\"date.html\">[date]</a>\n"
  141.             . "<a href=\"subject.html\">[subj]</a>\n" 
  142.             . "<a href=\"author.html\">[auth]</a>\n"
  143.             . "<h1>$title by author</h1>\n<p>\n"
  144.             . "<!-- AUTHOR: $author-->\n";
  145.         print OUT "<b>$author</b>\n<ul>\n";
  146.         print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
  147.         print OUT "</ul>\n";
  148.         print OUT "<!-- LAST -->\n";
  149.         close(OUT);
  150.     } else {
  151.         $author =~ /\s+(.*)$/;
  152.         $last_author = $1;
  153.         $not_done = 1;
  154.         open(IN, "< $author_file");
  155.         open(OUT, "> $dummy");
  156.         while(<IN>) {
  157.             $line = $_;
  158.             if ($not_done && $_ =~ /\<\!-- AUTHOR\: (.*)--/) {
  159.                 $la = $1;
  160.                 if ($author eq $la) { 
  161.                     &append; 
  162.                     $not_done = 0;
  163.                 } else { 
  164.                     $la =~ /\s+(.*)$/;
  165.                     $last = $1;
  166.                     if ($last_author gt $last) {
  167.                         print OUT $line;
  168.                         next;
  169.                     }
  170.                     &new_author;
  171.                     $not_done = 0;
  172.                     print OUT $line;
  173.                 }
  174.             } elsif ($not_done && $_ =~ /\<\!-- LAST --\>/) {
  175.                 &new_author;
  176.                 print OUT $_;
  177.             } else { print OUT $_; }
  178.         }
  179.         close(IN);
  180.         close(OUT);
  181.     
  182.         rename($dummy, $author_file);
  183.     }
  184. }
  185.  
  186. sub new_author {
  187.     print OUT "<!-- AUTHOR: $author-->\n";
  188.     print OUT "<b>$author</b>\n<ul>\n";
  189.     print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
  190.     print OUT "</ul>\n";
  191. }
  192.  
  193. sub append {
  194.     print OUT $line;
  195.     while(<IN>) {
  196.         if ($_ =~ /\<\/ul/) {
  197.             print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n"
  198.                 . "</ul>\n";
  199.             return;
  200.         } else { print OUT $_; }
  201.     }
  202. }
  203.  
  204. sub make_new_file {
  205.     $body =~ s/</</g;
  206.     $body =~ s/>/>/g;
  207.     $body =~ s/(http\:\/\/[a-zA-Z0-9\_\/\-\.]+)/\<a href=$1\>$1\<\/a\>/g;
  208.     $body =~ s/([a-zA-Z0-9\_\/\-\.]+\@[a-zA-Z0-9\_\/\-\.]+)/\<a href=\"mailto: $1\"\>$1\<\/a\>/g;
  209.     if ($body =~ /\n\-\-\s+\n/) {
  210.         @splt = split(/\n\-\-\s+\n/, $body);
  211.         $splt[0] =~ s/\n/<br>\n/g;
  212.         $splt[0] .= "<pre>";
  213.         $body = join("<br>\n--\n", @splt);
  214.         $body .= "</pre>";
  215.     } else {
  216.         $body =~ s/\n/<br>\n/g;
  217.     }
  218.  
  219.     open(OUT, "> $file");
  220.     print OUT "<!--\n"
  221.         . "$date\n"
  222.         . "$author\n"
  223.         . "$email\n"
  224.         . "$subject\n"
  225.         . "-->\n";
  226.     print OUT "<title>$title: $subject</title>\n"
  227.         . "<a href=\"date.html\">[date]</a>\n"
  228.         . "<a href=\"subject.html\">[subj]</a>\n" 
  229.         . "<a href=\"author.html\">[auth]</a>\n"
  230.         . "<h1>$subject</h1>\n"
  231.         . "$author (<i>$email</i>)<br>\n"
  232.         . "<i>$date</i>\n<p>\n<ul>\n";
  233.     if ($num > 0) {
  234.         print OUT "<li><b>Last message: </b>"
  235.         . "<a href=\"$last_url\">$last_author: $last_subject</a>\n";
  236.     }
  237.     print OUT "<!-- _NEXT_HERE_ -->\n";
  238.     print OUT "</ul>\n"
  239.         . "$body\n<p>\n<ul>\n";
  240.     if ($num > 0) {
  241.         print OUT "<li><b>Last message: </b>"
  242.         . "<a href=\"$last_url\">$last_author: $last_subject</a>\n";
  243.     }
  244.     print OUT "<!-- _NEXT_HERE_ -->\n";
  245.     print OUT "</ul>\n";
  246.     close(OUT);
  247. }
  248.  
  249. sub fix_last_file {
  250.     open(IN, "< $last_file");
  251.     open(OUT, "> $dummy");
  252.     while(<IN>) {
  253.         if ($_ =~ /_NEXT_HERE_/) { 
  254.             print OUT "<li><b>Next message: </b>"
  255.                 . "<a href=\"$url\">$author: $subject</a>\n";
  256.         } else { print OUT $_; }
  257.     }
  258.     close(IN);
  259.     close(OUT);
  260.     
  261.     rename($dummy, $last_file);
  262. }
  263.  
  264. sub get_previous {
  265.     if (-e $num_file) {
  266.         open(IN, "< $num_file");
  267.         $num = <IN>;
  268.         close(IN);
  269.  
  270.         for ($i=4; $i>length($num); $i--) { $f_num .= "0"; }
  271.         $f_num .= $num;
  272.         $file = "$root_dir/$f_num\.html";
  273.  
  274.         $last_num = $num-1;
  275.         for ($i=4; $i>length($last_num); $i--) { $f_lnum .= "0"; }
  276.         $f_lnum .= $last_num;
  277.         $last_file = "$root_dir/$f_lnum\.html";
  278.  
  279.         open(IN, "< $last_file");
  280.         $last_date = <IN>;
  281.         $last_date = <IN>;
  282.         $last_author = <IN>;
  283.         $last_email = <IN>;
  284.         $last_subject = <IN>;
  285.         close(IN);
  286.  
  287.         $url = $url_root . "/" . $f_num . ".html";
  288.         $last_url = $url_root . "/" . $f_lnum . ".html";
  289.     } else {
  290.         $num = 0;
  291.         $f_num = "0000";
  292.         $file = $root_dir . "/0000.html";
  293.         $url = $url_root . "/" . $f_num . ".html";
  294.         if (! -d $root_dir) { mkdir($root_dir, 0755); }
  295.     }
  296.     open(OUT, "> $num_file");
  297.     print OUT $num + 1;
  298.     close(OUT);
  299. }
  300.  
  301. sub get_letter {
  302.     while(<STDIN>) {
  303.         $need_subj = 1; $need_name = 1; $need_date = 1;
  304.         if ($need_name && $_ =~ /^From:\s+(.*)/)
  305.             { &get_from($1); $need_name = 0; }
  306.         elsif ($need_date && $_ =~ /^Date:\s+(.*)/) 
  307.             { $date = $1; $need_date = 0; }
  308.         elsif ($need_subj && $_ =~ /^Subject:\s+(.*)/) 
  309.             { $subject = $1; $need_subj = 0; }
  310.         elsif ($_ eq "\n") {
  311.             $save = $/; undef $/;
  312.             $body = <STDIN>;
  313.             $/ = $save;
  314.         }
  315.         if ($subject eq "") { $subject = "[no subject]"; }
  316.     }
  317. }
  318.  
  319. sub get_from {
  320.     if ($_[0] =~ /(.*)\s+\<(.*)\>/) {
  321.         $author = $1; $email = $2;
  322.         if ($author =~ /\"(.*)\"/) { $author = $1; }
  323.     } elsif ($_[0] =~ /(.*)\s+\((.*)\)/) {
  324.         $email = $1;
  325.         $author = $2;
  326.     } else {
  327.         $author = "name format error";
  328.         $email = "email format error";
  329.     }
  330. }
  331.